/*     */ package com.zimbra.cs.mailclient.imap;
/*     */ 
/*     */ import com.zimbra.cs.mailclient.ParseException;
/*     */ import com.zimbra.cs.mailclient.util.Ascii;
/*     */ import java.io.IOException;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public final class ListData
/*     */ {
/*     */   private String mailbox;
/*     */   private char delimiter;
/*     */   private Flags flags;
/*     */   
/*     */   public static ListData read(ImapInputStream is)
/*     */     throws IOException
/*     */   {
/*  46 */     ListData mb = new ListData();
/*  47 */     mb.readMailboxList(is);
/*  48 */     return mb;
/*     */   }
/*     */   
/*     */   private ListData() {}
/*     */   
/*     */   public ListData(String mailbox, char delimiter) {
/*  54 */     this.mailbox = mailbox;
/*  55 */     this.delimiter = delimiter;
/*  56 */     this.flags = new Flags();
/*     */   }
/*     */   
/*     */   private void readMailboxList(ImapInputStream is) throws IOException {
/*  60 */     is.skipSpaces();
/*     */     
/*  62 */     if (is.peek() == 40) {
/*  63 */       this.flags = readFlags(is);
/*  64 */       is.skipChar(' ');
/*     */     } else {
/*  66 */       this.flags = new Flags();
/*     */     }
/*  68 */     String delim = is.readNString();
/*  69 */     if (delim != null) {
/*  70 */       if (delim.length() != 1) {
/*  71 */         throw new ParseException("Invalid delimiter specification in LIST data: " + delim);
/*     */       }
/*     */       
/*  74 */       this.delimiter = delim.charAt(0);
/*     */     }
/*  76 */     is.skipChar(' ');
/*  77 */     is.skipSpaces();
/*  78 */     String s = is.peekChar() == '"' ? readQuoted(is) : is.readAString();
/*     */     
/*     */ 
/*  81 */     if ((is.peek() == 40) || (is.peek() == 41)) {
/*  82 */       s = s + is.readText("\r\n");
/*     */     }
/*  84 */     this.mailbox = MailboxName.decode(s).toString();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   private static String readQuoted(ImapInputStream is)
/*     */     throws IOException
/*     */   {
/*  92 */     is.skipChar('"');
/*  93 */     StringBuilder sb = new StringBuilder();
/*  94 */     while (is.peekChar() != '\r') {
/*  95 */       char c = is.readChar();
/*  96 */       if (c == '\\') {
/*  97 */         c = is.readChar();
/*     */       }
/*  99 */       sb.append(c);
/*     */     }
/* 101 */     String s = sb.toString();
/* 102 */     if (!s.endsWith("\"")) {
/* 103 */       throw new ParseException("Unexpected end of line while reading QUOTED string");
/*     */     }
/*     */     
/* 106 */     return s.substring(0, s.length() - 1);
/*     */   }
/*     */   
/*     */   private static Flags readFlags(ImapInputStream is) throws IOException {
/* 110 */     Flags flags = Flags.read(is);
/* 111 */     int count = 0;
/* 112 */     if (flags.isNoselect()) count++;
/* 113 */     if (flags.isMarked()) count++;
/* 114 */     if (flags.isUnmarked()) count++;
/* 115 */     if (count > 1) {
/* 116 */       throw new ParseException("Invalid LIST flags - only one of \\Noselect, \\Marked, or \\Unmarked expected: " + flags);
/*     */     }
/*     */     
/*     */ 
/* 120 */     return flags;
/*     */   }
/*     */   
/* 123 */   public Flags getFlags() { return this.flags; }
/* 124 */   public String getMailbox() { return this.mailbox; }
/* 125 */   public char getDelimiter() { return this.delimiter; }
/*     */   
/*     */   public String toString()
/*     */   {
/* 129 */     return String.format("{mailbox=%s, delimiter=%s, flags=%s}", new Object[] { this.mailbox, Ascii.pp((byte)this.delimiter), this.flags });
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/mailclient/imap/ListData.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */